package com.toe.admin.controller;

import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.user.UserReportArticleDTO;
import com.toe.pojo.dto.user.UserReportRemarkDTO;
import com.toe.pojo.vo.user.UserReportArticleVO;
import com.toe.pojo.vo.user.UserReportRemarkVO;
import com.toe.user.service.UserReportArticleService;
import com.toe.user.service.UserReportRemarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "后台举报模块")
@RequestMapping("/report")
public class ReportController {
    @DubboReference
    private UserReportArticleService dubboReportArticle;

    @DubboReference
    private UserReportRemarkService dubboReportRemark;

    @ApiOperation(value = "新增举报帖子")
    @PostMapping("/add/article")
    public JsonResult<Void> addReportArticle(@RequestBody UserReportArticleDTO userReportArticleDTO) {
        dubboReportArticle.addReportArticle(userReportArticleDTO);
        return JsonResult.ok();
    }

    @ApiOperation(value = "分页查询举报帖子")
    @GetMapping("/page/article/{pageNum}/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum",example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "5")
    })
    public JsonResult<JsonPage<UserReportArticleVO>> pageReportArticles(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        JsonPage<UserReportArticleVO> jsonPage = dubboReportArticle.pageReportArticle(pageNum, pageSize);
        return JsonResult.ok(jsonPage);
    }

    @ApiOperation(value = "帖子举报失败")
    @PostMapping("/forbid/article/{id}")
    public JsonResult<Void> forbidReportArticle(@PathVariable Long id) {
        dubboReportArticle.forbidArticle(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "帖子举报成功")
    @PostMapping("/pass/article/{id}")
    public JsonResult<Void> passReportArticle(@PathVariable Long id) {
        dubboReportArticle.passArticle(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "新增举报评论")
    @PostMapping("/add/remark")
    public JsonResult<Void> addReportRemark(@RequestBody UserReportRemarkDTO userReportRemarkDTO) {
        dubboReportRemark.addReportRemark(userReportRemarkDTO);
        return JsonResult.ok();
    }

    @ApiOperation(value = "分页查询举报评论")
    @GetMapping("/page/remark/{pageNum}/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum",example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "5")
    })
    public JsonResult<JsonPage<UserReportRemarkVO>> pageReportRemarks(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        JsonPage<UserReportRemarkVO> jsonPage = dubboReportRemark.pageReportRemark(pageNum, pageSize);
        return JsonResult.ok(jsonPage);
    }

    @ApiOperation(value = "评论举报失败")
    @PostMapping("/forbid/remark/{id}")
    public JsonResult<Void> forbidReportRemark(@PathVariable Long id) {
        dubboReportRemark.forbidRemark(id);
        return JsonResult.ok();
    }

    @ApiOperation(value = "评论举报成功")
    @PostMapping("/pass/remark/{id}")
    public JsonResult<Void> passReportRemark(@PathVariable Long id) {
        dubboReportRemark.passRemark(id);
        return JsonResult.ok();
    }

}
